// https://leetcode.cn/problems/minimum-operations-to-collect-elements/description/


func minOperations(nums []int, k int) int {
    rec := make(map[int]int)
	for i := 1; i < k + 1; i++ {
		rec[i] = 1
	}
	ans := 0
	for i := len(nums) - 1;i >= 0 && len(rec) > 0; i-- {
		_, exists = rec[nums[i]]
		if exists {
			delete(rec, nums[i])
		}
		ans += 1
	}
	return ans
}